
package com.insigma.business.qrcode.soldier.service.impl;

import com.insigma.business.qrcode.common.service.SequenceGenerator;
import com.insigma.business.qrcode.soldier.dao.PlacementEventRecordDao;
import com.insigma.business.qrcode.soldier.dto.PlacementEventRecordBSearcher;
import com.insigma.business.qrcode.soldier.dto.SequenceNameConstant;
import com.insigma.business.qrcode.soldier.entity.PlacementEventRecordDO;
import com.insigma.business.qrcode.soldier.entity.PlacementSoldierInfoDO;
import com.insigma.business.qrcode.soldier.service.PlacementEventRecordService;
import com.insigma.business.qrcode.soldier.service.PlacementSoldierInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("placementEventRecordService")
public class PlacementEventRecordServiceImpl implements PlacementEventRecordService {

    @Autowired(required = false)
    private PlacementEventRecordDao placementEventRecordDao;
    @Autowired(required = false)
    private SequenceGenerator sequenceGenerator;
    @Autowired
    private PlacementSoldierInfoService placementSoldierInfoService;
    
    @Override
    public List<PlacementEventRecordDO> search(final PlacementEventRecordBSearcher placementEventRecordBSearcher) {
        return placementEventRecordDao.search(placementEventRecordBSearcher);
    }
   
    @Override
    public PlacementEventRecordDO get(final String id){
        return placementEventRecordDao.get(id);
    }

    
    @Override
    public Integer insert(final PlacementEventRecordDO placementEventRecordDO){
        placementEventRecordDO.setId(sequenceGenerator.genKey(SequenceNameConstant.PLACEMENT_EVENT_RECORD_ID));
        return placementEventRecordDao.insert(placementEventRecordDO);
    }

    
    @Override
    public Integer update(final PlacementEventRecordDO placementEventRecordDO){
        return placementEventRecordDao.update(placementEventRecordDO);
    }

    
    @Override
    public Integer delete(final String id, final String modifierType, final String modifierId){
        return placementEventRecordDao.delete(id,modifierType,modifierId);
    }

    @Override
    public List<PlacementEventRecordDO> listBySoldierId(String soldierId) {
        String idCardNo = placementSoldierInfoService.getIdCardNoBySoldierId(soldierId);
        return placementEventRecordDao.listByIdCardNo(idCardNo);
    }

    @Override
    public Integer insertEventRecord(String soldierId, String idCardNo, String realName, String msg) {
        PlacementEventRecordDO event = new PlacementEventRecordDO();
        event.setSoldierId(soldierId);
        event.setIdCardNo(idCardNo);
        event.setRealName(realName);
        event.setDetail(msg);
        return insert(event);
    }

    @Override
    public Integer insertEventRecord(String idCardNo, String msg) {
        PlacementSoldierInfoDO byIdCardNo = placementSoldierInfoService.getByIdCardNo(idCardNo);
        if (byIdCardNo != null) {
            PlacementEventRecordDO event = new PlacementEventRecordDO();
            event.setSoldierId(byIdCardNo.getSoldierId());
            event.setIdCardNo(idCardNo);
            event.setRealName(byIdCardNo.getRealName());
            event.setDetail(msg);
            return insert(event);
        }

        return 0;
    }

}
